/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.World;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 * @author Daniel
 */
public class MapInterpret {

    public static World translateFromMap(File in, ArrayList<BufferedImage> texture) {

        //W és el ground que té al damunt. Si li passa null és que és el ground
            //Superior. (això és per evitar flickering, o 2D clipping, és a dir,
            //Que dos boxels pintin el mateix alhora.
        
        World out = new World();

        try {
            BufferedImage mapaux = ImageIO.read(in);
            BufferedImage[][] map = new BufferedImage[mapaux.getHeight()][mapaux.getWidth()];

            out.set_height(mapaux.getHeight());
            out.set_width(mapaux.getWidth());

            for (int i = 0; i < mapaux.getHeight(); i++) {
                for (int j = 0; j < mapaux.getWidth(); j++) {
//                    System.out.println(mapaux.getRGB(j, i));
                    /*TODO: Add more textures, etc -- still a WIP!*/

//                    System.out.println(i+", "+j);
                    if (mapaux.getRGB(j, i) == -16777216) {
                        map[i][j] = texture.get(5);
                    } else if(mapaux.getRGB(j, i) == -1){
                        map[i][j] = texture.get(0);
                    } else if(mapaux.getRGB(j, i) == -13032926){
                        map[i][j] = texture.get(9);
                    }else{
                        map[i][j] = texture.get(10);
                    }
                }
            }

            out.set_map(map);

            return out;
        } catch (IOException ex) {
            Logger.getLogger(MapInterpret.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return out;
    }

    public static World translateText(String in, ArrayList<BufferedImage> Texture) {
        String fontcontent = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                + "abcdefghijklmnopqrstuvwxyz"
                + "1234567890.,$";
//
//        World out = null;
//        
//        char[] aux = new char[1];
//
//        for (int i = 0; i < in.length(); i++) {
//            aux[1] = in.charAt(i);
//            try {
//                
//            } catch (Exception e) {
//            }
//        }

        return null;
    }

}
